package com.wind.taobao.api.trade.itemprop.convert
{
	import com.wind.taobao.api.trade.itemprop.model.Brand;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;


	/**
	 * Brand转换器
	 * @author fxy
	 *
	 */
	public class BrandConvert
	{
		/**
		 * 转换Brand集合
		 */
		public static function convertBrands(value:Object, type:String="json"):ArrayCollection
		{
			var brands:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							brands.addItem(convertBrand((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return brands;
		}

		/**
		 * 转换Brand
		 */
		public static function convertBrand(value:Object, type:String="json"):Brand
		{
			var brand:Brand=new Brand();
			if (value == null)
				return brand;
			if (type == TaobaoConstants.XML)
			{
				brand=convertXMLToBrand(XML(value), brand);
			}
			else
			{
				brand=convertJSONToBrand(value, brand);
			}
			return brand;
		}

		/**
		 * JSON转换为Brand
		 */
		private static function convertJSONToBrand(json:Object, brand:Brand):Brand
		{
			if (json.hasOwnProperty(TaobaoConstants.VID))
			{
				brand.vid=json[TaobaoConstants.VID];
			}
			if (json.hasOwnProperty(TaobaoConstants.NAME))
			{
				brand.name=json[TaobaoConstants.NAME];
			}
			return brand;
		}

		/**
		 * XML转换为Brand
		 */
		private static function convertXMLToBrand(value:XML, brand:Brand):Brand
		{
			return brand;
		}
	}
}